{include file="public/head"/}
<div class="layui-fluid" id="LAY-app-message">
    <div class="layui-card">
        <div class="layui-card-header">存储配置</div>
        <div class="layui-card-body">
            <div class="table-head-btn" style="margin-bottom: 10px;">
                <div class="layui-inline">
                    <input class="layui-input" name="key" id="key" placeholder="请输入关键字" autocomplete="off">
                </div>
                <button class="layui-btn" data-type="reload">搜索</button>
            </div>
            <table class="layui-hide" id="list" lay-filter="list"></table>
        </div>
    </div>
</div>
{include file="public/foot"/}
<script type="text/html" id="status">
    <input type="checkbox" name="status" value="{{d.id}}" lay-skin="switch" lay-text="正常|禁用" lay-filter="status" {{ d.status == 1 ? 'checked disabled' : '' }}>
</script>
<script type="text/html" id="action">
        {{#  if(d.id==1){ }}
		<button  class="layui-btn layui-btn-xs layui-btn-disabled"><i class="layui-icon layui-icon-table"></i>配置</button>
		{{# }else{ }}
		<button class="layui-btn layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-table"></i>配置</button>
        {{#  } }}
    

</script>
<script>
    layui.config({
        base: '__LAYDMIN__/',{if config('app.app_debug')}version: true{/if}
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','table','form'],function(){
			var $ = layui.$, admin = layui.admin, table = layui.table, element = layui.element, form = layui.form,util = layui.util;
			var tableLoadDiv = window.top.layer.load(0,{shade:[0.15, '#000']}); //加载层,table.render完成时需要关闭
			//全部数据
			tableIn = table.render({
				elem: '#list',
				url: '{:url(SYS_PATH."/".CONTROLLER."/index")}',
				method: 'post',
				autoSort: false,
				cols: [[
					{type: 'checkbox'},
					{field: 'id', title: 'ID', width: 50},
					{field: 'name', title: '名称', width: 120},
					{field: 'desc', title: '描述', width: 400,sort:true},
					{field: 'status', align: 'center', title: '状态', width: 120, toolbar: '#status'},
					{field: 'update_time', title: '修改时间', width: 200,sort:true,templet: function(d){
							return util.toDateString(d.update_time*1000,'yyyy-MM-dd HH:mm:ss');
						}},
					{width: 100, align: 'center', toolbar: '#action',title:'操作'}
				]],
				page: true,
				done:function (res) {   //返回数据执行回调函数
			    	window.top.layer.close(tableLoadDiv);    //返回数据关闭loading
			    }					
			});	
			
		//列表编缉与删除---监听工具条
		table.on('tool(list)', function (obj) {
					var data = obj.data;
					var id = data.id;
					if (obj.event === 'edit') {
						layui.layerOpen("{:url(SYS_PATH.'/'.CONTROLLER.'/edit')}?id="+id,data.name);
					}
		});			
			
			
		//改变会员状态
		form.on('switch(status)', function (obj) {
			var id = this.value;
			var status = obj.elem.checked === true ? 1 : 0;
			admin.req({
				url: '{:url(SYS_PATH.'/'.CONTROLLER.'/doStatus')}'
				, type: 'post'
				, data: {'id': id, 'status': status}
				, success: function (res) {
					if (res.code==0) {
						window.top.layer.msg(res.msg, {time: 1000, icon: 1,shade:[0.5,'#000']});
						tableIn.reload();
					} else {
						if (obj.elem.checked == true) {
							$(obj.elem).prop('checked', false);
						} else {
							$(obj.elem).prop('checked', true);
						}
						form.render();
					}
				}
			});
		});
		
    $('.table-head-btn .layui-btn').on('click', function () {
		
        var type = $(this).data('type');
		if (type === 'reload') {
            var key = $('#key').val();
            //执行重载
            table.reload('list', {
                page: {curr: 1 }, 
				where: {
					key: key
				}
            });
		}		
    });					
			
			
			
				
	});
</script>
</body>
</html>